package 常见的算法.排序算法.冒泡排序算法.test01;

public class BubbleSort {
    public static void main(String[] args) {
        int count = 0;
        int[] arr = {3,45,78,1212,99,56,87};
        for (int i = arr.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                count++;
                if(arr[j] > arr[j+1]){
                    int temp;
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }

            }
        }
        System.out.println("比较次数：" + count);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}
